import axios from 'axios'
import qs from 'qs'

const instance = axios.create({
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
})
instance.defaults.transformRequest = [function(data) {
    return qs.stringify(data)
}]
instance.install = function(Vue) {
    instance.interceptors.request.use(function(config) {
        // if (config.url !== '/login/auth/realms/sadan/protocol/openid-connect/token') {
        //     config.headers.access_token = sessionStorage.getItem('access_token')
        //     config.headers.refresh_token = sessionStorage.getItem('refresh_token')
        //     config.headers.session_state = sessionStorage.getItem('session_state')
        //     config.headers.token_type = sessionStorage.getItem('token_type')
        // } 
        return config;
    }, function(error) {
        return Promise.reject(error);
    });
    instance.interceptors.response.use(function(response) {
        return response;
    }, function(error) {
        return Promise.reject(error);
    });
    Vue.prototype.$axios = instance;
};
export default instance